Skip to main content

Relations

Often a database has multiple tables that have links to each other. For example, in UniFi the 'created_by' field doesn't store all the details related to the user who started the transaction, but a unique reference that is also stored on the user table where other details such as full name, email address etc. are held. To use this kind of linked data on a report you have to create a 'relation'.

Parent-child relations

Relations in UniFi BI are created as parent-child, also known as 'one-to-many' relations. The parent is a single record in one table (e.g. a user of a system) who may have many 'children' (multiple transactions that this user has created or approved). To create a new relation, right click anywhere in the dictionary and select 'New Relation', or you can access this from the 'New Item' menu at the top of the dictionary tab. Give it a meaningful name and select the parent and child tables. From each table you can then select the piece of data that is common to each table and click OK.

 alt image

tip

If an app contains a table and you want to use data from both the header and table of that app, then you should create a relation between the two. When a table is created, a system field is also created as the app id name but with '_id' appended (e.g. a table in 'purchase_invoice' app will have a field of 'purchase_invoice_id' in the table). You should create a relation of 'id' in the purchase_invoice table (the parent) to purchase_invoice_id (the child) in the table.

You can view your relations in the tables in the data dictionary.

 alt image

warning

When basing a report on child data, to use parent data drag it across from the expanded 'relation' area of the dictionary not the main header table to ensure that the data is linked correctly. For example, if you are creating an 'invoice' report containing transactions from a table plus header information (customer name, address etc.), drag the header details from the expanded relation within the table (HeaderTable in the above example).